package ThreadPool;

import lombok.extern.slf4j.Slf4j;
import lombok.val;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;

public class ThreadPool {


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService poolExecutor = new ThreadPoolExecutor(10, 10, 10L, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(100), new ThreadPoolExecutor.AbortPolicy());

/*        poolExecutor.submit(new Runnable() {
            public void run() {
                for (int i = 0 ; i < 100 ; i ++){
                    System.out.println(i+Thread.currentThread().getName());
                }
            }
        });*/
        List<String> list = new ArrayList();
        for (int i = 0 ; i < 100 ; i ++){
            list.add(String.valueOf(i));
        }

        int i = 0;
        for(String str : list){
            ++i;
            int finalI = i;
            Future<String> future = poolExecutor.submit(new Callable<String>() {
                @Override
                public String call() {
                    return print("finalI:"+finalI);
                }
            });
            /*future.get();*/
        }

    }

    public static String print(String s){
        System.out.println("s:" + s + "," + Thread.currentThread().getName());
        return "test";
    }

}
